#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<iostream>

using namespace std;

int mod = 100000007;

void TrackBack(vector<int>& v, int n, int start, vector<vector<int>>& ret)
{
	if (start == n)
	{
		ret.push_back(v);
		return;
	}

	for (int i = start; i < n; i++)
	{
		swap(v[i], v[start]);
		TrackBack(v, n, start + 1, ret);
		swap(v[i], v[start]);
	}
}

int maxSumRangeQuery(vector<int>& nums, vector<vector<int>>& requests)
{
	vector<vector<int>> v;
	TrackBack(nums, nums.size(), 0, v);
	int size = v.size(), Max = 0;
	for (int i = 0; i < size; i++)
	{
		vector<int> dp(size + 1, 0);
		for (int j = 1; j <= v[i].size(); j++)
		{
			dp[j] = dp[j - 1] + v[i][j - 1];
		}
		int sum = 0;
		for (int j = 0; j < requests.size(); j++)
		{
			sum += dp[requests[j][1] + 1] - dp[requests[j][0]];
			sum %= mod;
		}
		Max = max(sum, Max);
	}
	return Max;
}

int main()
{
	vector<int> nums = { 1,2,3,4,5 };
	vector<vector<int>> requests = { { 1,3 }, { 0, 1 } };
	cout << maxSumRangeQuery(nums, requests) << endl;

	return 0;
}